package cyou.breathe.blog.notice.domain.service;

import cyou.breathe.blog.notice.infrastructure.exception.NoticeException;
import org.springframework.stereotype.Component;

import java.util.List;

import static cyou.breathe.blog.notice.infrastructure.exception.NoticeErrorCode.NOT_SUIT_SENDER;

/**
 * @author: breathe
 * @createTime: 2025-08-27
 */
@Component
public class MessageSenderFactory {
    private final List<MessageSender> senders;

    public MessageSenderFactory(List<MessageSender> senders) {
        this.senders = senders;
    }

    public MessageSender getSender(String number) {
        return senders.stream()
                .filter(sender -> sender.supports(number))
                .findFirst()
                .orElseThrow(() -> new NoticeException(NOT_SUIT_SENDER));
    }
}
